Title: Add the quantity field to the [add_to_cart] shortcode

Publish Date: Mon, 04 May 2015 09:40:03 +0000

Categories: Programming

Tags: WooCommerce, WordPress

Content:

This article is outdated. WooCommerce blocks are the simplest, most flexible way to display products on posts and pages. They offer better customization options than the old WooCommerce shortcodes such as [add_to_cart]. Learn more about WooCommerce blocks.



With WooCommerce you have some shortcodes available to use anywhere on your site.



One of them is the shortcode [add_to_cart] which allows printing the Add to Cart button for a specific product on your site.



It only shows the button, though; you can't choose the quantity of that product without going to the cart page first. You can include the quantity field by tweaking the default template.









[download id="566"]



Download the zip above and extract it. Put the file add-to-cart.php in wp-content/themes/your-theme-name/woocommerce/loop/. This path may not exist; if it's your case, create it and then paste the file in it.
